#include <stdio.h>
#include <string.h>



main()
{
	int i;
	int n;
	int shu[10][2];
	int c0,c1;
	int an[1001];

//	while (scanf("%d", &n)!=EOF)
	{
	//	if (n>1000) n%=1000;
		shu[0][0]=shu[0][1]=1;
		shu[1][0]=1;
		shu[1][1]=1;
		shu[2][0]=2;
		shu[2][1]=2;
		shu[3][0]=4;
		shu[3][1]=2;

		an[0]=1;
		an[1]=2;
		an[2]=4;
		an[3]=6;
		for (i=4;i<=1000;i++)
		{
			c1=(shu[3][1]-shu[0][0]+shu[3][0]-shu[2][1])%2005;
			c0=(shu[3][1]+shu[3][0])%2005;
			if (c1<0) c1+=2005;
			if (c0<0) c0+=2005;
			memcpy(shu,shu+1,sizeof(int)*6);
			/*			for (j=0;j<=2;j++) 
			{
				shu[j][0]=shu[j+1][0];
				shu[j][1]=shu[j+1][1];
			}*/
			shu[3][0]=c0;
			shu[3][1]=c1;
			an[i]=(c0+c1)%2005;
		}
	
	}
	while (scanf("%d", &n)!=EOF)
	{
		int nn;
		nn=n%1000;
		printf("%d\n", an[nn]);
	}


	
	return 0;
}